<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户个人信息管理</title>
    <link href="../bootstrap-3.3.7-dist/css/bootstrap.min.css"  rel="stylesheet"  type="text/css" >
</head>

<tbody>
<form action="" method="get">
    <table class="table"  style="border-collapse: separate;border-spacing: 40px 5rem;">
        <input type="hidden" id="current_user_id">
        <input type="hidden" id="current_image_path">
        <tr>
            <td>头像:</td>
            <td>
                <img id="Image" alt="头像显示失败" title="点击头像可切换头像" onclick="changeImage()"
                     style="width: 150px;height: 150px;">
            </td>
        </tr>

        <tr>
            <td>用户昵称:</td>
            <td>
                <textarea name="info" id="nickName" rows="5" cols="80"></textarea>
            </td>
        </tr>


       <!-- <tr>
            <td>用户名:</td>
            <td>
                <textarea name="info" id="signature_info" rows="1" cols="80"></textarea>
            </td>
        </tr>
-->

      <!--  <tr>
            <td>性别:</td>
            <td>
                <input type="radio" name="u_sex" id="boy"  value="男" />男
                <input type="radio" name="u_sex" id="girl" value="女" />女
                <input type="radio" name="u_sex" id="secert" value="保密" />保密
            </td>
        </tr>-->

        <!--<tr>
            <td>生日:</td>
            <td>
                &lt;!&ndash; 使用其他控件代替 &ndash;&gt;
                <input type="date" name="u_bir" id="birth" value="2000-01-01"/>
            </td>
        </tr>-->

        <!--<tr>
            <td>手机号:</td>
            <td>
                <textarea name="u_name" id="email" rows="1" cols="80" /></textarea>
            </td>
        </tr>-->

        <!--<tr>
            <td>账户余额:</td>
            <td>
                <textarea name="info" id="balance" rows="1" cols="80"></textarea>
            </td>
        </tr>-->


        <tr>
            <td>
                <button  type="button" class="btn btn-info" style="margin-left: 1.25rem;" onclick="saveEdition()">保存修改</button>
            </td>
        </tr>

        <tr>
            <td>
                <button  type="button" class="btn btn-info" style="margin-left: 1.25rem;" onclick="test()">当前用户信息</button>
            </td>
        </tr>


    </table>
</form>



</tbody>

<script src="../jquery/jquery-3.4.1.min.js"></script>
<script src="../bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script type="text/javascript">
    jQuery(function() {

        jQuery.post("/getAllUserInfo",function(rst){

            /**
             * CurrentUserId为当前使用者的userName
             *
             * 将从cookie获取的usr_no赋给它
             *
             * @type {number}
             */
            var cookies=document.cookie.split(";");
            for(var i=0;i<cookies.length;i++)
            {
                var cookie=cookies[i].trim();
                if(cookie.indexOf("usr_no")==0)
                {
                    var CurrentUserNo=cookie.substring("usr_no".length+1);
                }
            }

            for(var i=0;i<rst.length;i++)
            {
                var json=rst[i];
                if(json.target==CurrentUserNo)
                {
                    var CurrentUserId=i;
                    break;
                }
            }


            var json=rst[CurrentUserId];

            jQuery("#current_user_id").val(json.id);
            //头像
            //Todo
            var imagePath=json.image;
            $("#Image").attr('src',imagePath);
            jQuery("#current_image_path").val(imagePath);

            //签名
            document.getElementById("signature_info").innerHTML=json.signature;

            //性别
            $("input[type=radio][name='u_sex'][value="+json.sex+"]").attr("checked",true);

            /**
             * $("input[name='u_sex']").each(function (index,element) {

                if($(this).val==json.sex){
                    $(this).prop("checked",true);
                }
            })
             */
                //生日
            var birthDate=json.birth;
            $('#birth').val(birthDate);

            //邮箱
            document.getElementById("email").innerHTML=json.email;

            //个人说明
            document.getElementById("description_info").innerHTML=json.description;
        },"json");
    });

    function test(){
        let targetName = $.cookie("username");
        let targetId = $.cookie("userid");
        alert("id: " + targetId + "username: " + targetName);
        jQuery.post("/getUserInfoByName", {"userName" : target}, function (rst) {
            var info = rst.userNickname;
            alert(info);
            alert("here3");
        })
    }

    function saveEdition() {

        var str = "路飞";

        /*jQuery.post("/getUserInfoByName", {"userName" : str}, function (rst) {
            alert("here2");
            var info = rst.userNickname;
            alert(info);
            alert("here3");
        })*/


        var id = 1;
        alert("id = " + id);
        jQuery.post("/getUserInfoById", {"userId" : id}, function (rst) {
            var info = rst.userNickname;
            alert(info);
        })

       /* var id=jQuery("#current_user_id").val();

        var signature=jQuery("#signature_info").val();

        var sex=$("input[type='radio']:checked").val();

        var birth=jQuery("#birth").val();

        var email=jQuery("#email").val();//

        var description=jQuery("#description_info").val();*/

        jQuery.post("/editPI",{"id":id,"signature":signature,"sex":sex,"birth":birth,"email":email,"description":description},function (rst) {
            alert(rst);
            if(rst=="修改成功")
            {
                window.parent.location.replace("main.html");
            }
        })

    }



</script>
</html>
